{extend name="public:layout" /}
{block name="title"}客户结算{/block}
{block name="head"}
<style>
    @media print {
        .noprn{ display:none;}
        input[class='print']{border:none;}
    }
</style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <h1 style="text-align:center;">{$btypeinfo.title}账目清算单{$rangdate}</h1>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-content p-xl">
                <table width="100%">
                    <tr>
                        <td width="50%">
                            <address>
                                <strong>所属单位：{$btypeinfo.company}</strong><br>
                                <strong>客户名称:{$btypeinfo.title}</strong><br>
                                联系电话：{$btypeinfo.btype_phone}<br/>
                                联系地址：{$btypeinfo.btype_address}<br/>
                                订单总额：{$sum.sum_order_charge}元
                            </address>
                        </td>
                        <td width="50%" style="text-align:right">
                            <address>
                                开户行：{$btypeinfo.btype_bank}<br>
                                银行账号：{$btypeinfo.btype_account}<br>
                                挂账额度：{$btypeinfo.credit_line}<br>
                                欠款金额：<span style="font-size:24px;color:#ff3b30">{$sum.sum_order_q}</span>元<br>
                            </address>
                        </td>
                    </tr>
                </table>
                <form class="form-inline noprn">
                    <div class="form-group">
                        <label>客户回款</label>
                        <input type="text" class="form-control" id="sum_money" value="0" />
                    </div>
                    <button type="button" class="btn btn-info" onclick="autocalc();">自动分配</button>
                </form>
                <form id="form" method="post">
                    <div class="table-responsive m-t">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>行程单</th>
                                <th>司机</th>
                                <th>接车联系人</th>
                                <th>日期</th>
                                <th>订单金额</th>
                                <th>定金</th>
                                <th>已付款</th>
                                <th>欠款金额</th>
                                <th width="150">收款金额</th>
                                <th width="150">优惠金额</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td><strong>{$vo.title}</strong></td>
                                <td>{$vo.fleet_driver}</td>
                                <td>{$vo.guide}({$vo.guide_tel})</td>
                                <td>[{$vo.order_start_time}]-[{$vo.order_end_time}]</td>
                                <td>{$vo.order_charge}</td>
                                <td>{$vo.order_advance}</td>
                                <td>{$vo.order_pay}</td>
                                <td>{$vo.order_q}</td>
                                <td>
                                    <input datatype="*" class="form-control print" type="text" name="order[{$vo.aid}][pay_money]" value=""/>
                                </td>
                                <td>
                                    <input datatype="*" class="form-control print" type="text" name="order[{$vo.aid}][discount_money]" value="{$vo.discount_money|default=0}"/>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                    <!-- /table-responsive -->
                    <div class="text-right noprn">
                        <a href="/system/logic.order/paymoney.html" class="btn btn-white">取消</a>
                        <button type="button" id="btnSub" class="btn btn-primary"><i class="fa fa-dollar"></i> 去收款</button>
                        <button type="button" onclick="window.print();" class="btn btn-info">打印</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
    <script>
        $(function () {
            ajaxSubForm('#btnSub');
        });
        //自动计算
        function autocalc() {
            $('.table tbody tr').each(function () {
                var sum_money=parseFloat($('#sum_money').val());
                if(sum_money>0){
                    var tdArr = $(this).children();
                    var order_q = tdArr.eq(7).text();//欠款
                    if(sum_money<order_q){ //不够付欠款
                        tdArr.eq(8).find('input').val(sum_money);
                        $('#sum_money').val(0);
                    }else{
                        tdArr.eq(8).find('input').val(order_q);
                        $('#sum_money').val(sum_money-order_q);
                    }
                }
            });
        }
    </script>
{/block}